package com.test.springboot.demo.util;

public class IpUtil {

    public static boolean checkIp(String ip) {
        if (ip == null || ip.trim().length() == 0) {
            return false;
        }
        String[] nums = ip.split("\\.");
        if (nums.length != 4) {
            return false;
        }
        for (String num : nums) {
            try {
                Integer n = Integer.parseInt(num);
                if (n < 0 || n > 255) {
                    return false;
                }
            } catch (NumberFormatException e) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(checkIp("127.0.0"));
    }
}
